﻿@model ADZ_JingjiaMaster
@{
    ViewBag.Title = "竞价编辑";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    var viewModel = Model ?? new ADZ_JingjiaMaster();
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
    ADZ_JingjiaConfig config = null;
    if (viewModel.jingjia_config_id > 0)
    {
        config = dbcontext.ADZ_JingjiaConfig.FirstOrDefault(t => t.jingjia_config_id == viewModel.jingjia_config_id);
    }
}

<form id="S_Form" action="@Url.Action("add", "jingjia")" method="post" class="definewidth m20" enctype="multipart/form-data">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="4" style="width:50%">
                <h5>@ViewBag.Title @(viewModel.jingjia_id > 0 ? "竞价编号：" + viewModel.jingjia_id : "")  @(config != null ? ($"属于竞价配置【{config.jingjia_config_name}】") : ("")) </h5>
                <input type="hidden" value="@viewModel.jingjia_id" name="jingjia_id" id="jingjia_id" />
                <input type="hidden" value="@viewModel.jingjia_config_id" name="jingjia_config_id" id="jingjia_config_id" />
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">竞价图片<em>*</em></td>
            <td colspan="3">
                @{
                    OneImgModel oneImgModel = new OneImgModel();
                    oneImgModel.img_url = viewModel.img_url;
                    oneImgModel.showdel = true;
                    oneImgModel.remark = "设置竞价图片";
                    Html.RenderPartial(Url.Content("~/Views/Common/ImgsOneCommon.cshtml"), oneImgModel);
                }
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">竞价包名称<em>*</em></td>
            <td>
                <input type="text" name="jingjia_name" style="width:300px;" value="@Model.jingjia_name" />
            </td>
            <td width="6%" class="tableleft">竞价状态<em>*</em></td>
            <td>
                <input type="radio" name="jingjia_satus" style="vertical-align:middle; margin-bottom:6px;" value="0" />未开始
                <input type="radio" name="jingjia_satus" style="vertical-align:middle; margin-bottom:6px;" value="1" />竞价中
                <input type="radio" name="jingjia_satus" style="vertical-align:middle; margin-bottom:6px;" value="2" />已结束
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">起拍价<em>*</em></td>
            <td>
                <input type="text" name="base_price" style="width:300px;" value="@Model.base_price" />
            </td>
            <td width="6%" class="tableleft">是否含税<em>*</em></td>
            <td>
                <input type="radio" name="include_tax" style="vertical-align:middle; margin-bottom:6px;" value="0" />未含税
                <input type="radio" name="include_tax" style="vertical-align:middle; margin-bottom:6px;" value="1" />含税
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">加价幅度<em>*</em></td>
            <td>
                <input type="text" name="step_price" style="width:80px;" value="@Model.step_price" />至<input type="text" name="step_price_max" style="width:80px;" value="@Model.step_price_max" />（最大值为0表示不限制最大加价）
            </td>
            <td width="6%" class="tableleft">延时周期<em>*</em></td>
            <td>
                <input type="text" name="stay_miniutes" style="width:300px;" value="@Model.stay_miniutes" />分钟/次
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">留置价<em></em></td>
            <td>
                <input type="text" name="liuzhi_price" style="width:300px;" value="@Model.liuzhi_price" />
            </td>
            <td class="tableleft">备注</td>
            <td><textarea name="remark" style="width:80%;" maxlength="550" cols="4">@Model.remark</textarea></td>
        </tr>

        <tr>
            <td class="tableleft"></td>
            <td colspan="3">
                <p><span id="spMsg"></span></p>
                <button type="submit" class="btn btn-primary">保存</button> &nbsp;&nbsp;
                @if (viewModel.jingjia_id > 0)
                {
                    <button type="button" backpageid="jingjia/getlist" class="btn btn-success" name="backid" id="backid">返回列表</button>
                }
            </td>
        </tr>
        @if (config != null)
        {
            <tr>
                <td width="6%" class="tableleft">竞价起止时间</td>
                <td colspan="3">
                    @config.begin_time.ToString(1) -- @Model.real_end_time.ToString(1)
                </td>
            </tr>
        }
        @if (viewModel.jingjia_id > 0)
        {
            <tr>
                <td colspan="4" align="left">
                    <table align="left" style="width:750px;" class="table table-bordered table-hover definewidth m10">
                        <tr>
                            <td>
                                报名人数：
                            </td>
                            <td>
                                @{
                                    if (config != null)
                                    {
                                        <info>@config.baoming_counts</info>
                                    }
                                }
                            </td>
                            <td>最后出价金额：</td>
                            <td>
                                @Model.last_price
                            </td>
                        </tr>
                        <tr>
                            <td>
                                出价次数：
                            </td>
                            <td> @Model.chujia_counts</td>
                            <td>
                                最后出价时间：<br />
                            </td>
                            <td>@Model.last_time.ToString(1)</td>
                        </tr>
                        <tr>
                            <td>
                                围观次数：
                            </td>
                            <td> @Model.weiguan_counts</td>
                            <td>
                                最后出价人：<br />
                            </td>
                            <td>
                                @{
                                    var jingjiainfo = dbcontext.ADZ_JingjiaSubmit.OrderByDescending(t => t.seq_id).FirstOrDefault(t => t.jingjia_id == viewModel.jingjia_id);
                                    if (jingjiainfo != null && jingjiainfo.uid > 0)
                                    {
                                        var userinfo = dbcontext.ADZ_MemberMaster.FirstOrDefault(t => t.uid == jingjiainfo.uid);
                                        if (userinfo != null)
                                        {
                                            <info><a href="/account/accountlist?account_mobile=@userinfo.account_mobile&beg_time=2019-01-01"> @userinfo.member_name @userinfo.account_mobile </a></info>
                                        }
                                    }
                                }
                                @if (viewModel.jingjia_satus == 2)
                                {
                                    if (viewModel.chujia_counts > 0 && viewModel.jingjia_deal_status == 2)
                                    {
                                        <info class="green">已成交</info>
                                        var jingjiaSubmit = dbcontext.ADZ_JingjiaSubmit.FirstOrDefault(t => t.jingjia_id == viewModel.jingjia_id && t.is_hit == 1);
                                        if (jingjiaSubmit != null)
                                        {
                                            if (jingjiaSubmit.status == 2)
                                            {
                                                <info class="red">未付款 <a href="/OrderMaster/OrderMasterInfo/@jingjiaSubmit.order_master_id">查看订单</a></info>
                                            }
                                            if (jingjiaSubmit.status == 10)
                                            {
                                                <info class="green">已付款 <a href="/OrderMaster/OrderMasterInfo/@jingjiaSubmit.order_master_id">查看订单</a></info>
                                            }
                                        }
                                    }
                                    else
                                    {
                                        <info class="red">已流拍</info>
                                    }
                                }
                            </td>
                        </tr>
                    </table>


                </td>
            </tr>
        }
    </table>
    @if (viewModel.jingjia_id > 0)
    {
        <h5>商品列表  <a href="/jingjia/editgoods?jingjia_id=@viewModel.jingjia_id">编辑商品信息</a></h5>
        <table class="table table-bordered table-hover definewidth m10">
            <thead>
                <tr>
                    <th style="width:70px">图片</th>
                    <th>料号</th>
                    <th>品牌</th>
                    <th>分类</th>
                    <th>供应商</th>
                    <th>DC号</th>
                    <th>上架时间</th>
                    <th>是否含税</th>
                    <th>库存数量</th>
                    <th>备注</th>
                    <th></th>
                </tr>
            </thead>
            @{
                var goods_ids =
                    from t in dbcontext.ADZ_GoodsJingjia
                    where t.jingjia_id.Equals(viewModel.jingjia_id)
                    select t.goods_id;

                var good_list = dbcontext.Views_Goods.Where(t => goods_ids.Contains(t.goods_id) && t.is_del == 0);

                int index = 0;
                foreach (var m in good_list)
                {
                    index++;
                    <tr class="@HtmlPagerHelper.TrClass(index)">
                        <td>
                            @{
                                var aDZ_GoodsIMGs = dbcontext.ADZ_GoodsIMG.Where(t => t.goods_id == m.goods_id);
                                foreach (var item in aDZ_GoodsIMGs.OrderBy(t => t.sort_NO))
                                {
                                    <a href="@ImageFileBiz.GetImg(item.img_url)" target="_blank"> <img style="width:30px;margin:1px 1px 1px 1px;" src="@ImageFileBiz.GetImg(item.img_url,"small")" /></a>
                                }
                            }
                        </td>
                        <td>@m.MPN</td>
                        <td>@m.brand_name</td>
                        <td>@m.category_name</td>
                        <td>@m.supplier_name</td>
                        <td>@m.DCN</td>
                        <td>@m.with_up_time.ToString(1)</td>
                        <td>
                            @if (m.include_tax == 0)
                            {
                                <info>未含税</info>
                            }
                            else if (m.include_tax == 1)
                            {
                                <info class="green">含税</info>
                            }
                        </td>
                        <td>@m.stock_amount @m.goods_unit</td>
                        <td>@m.product_desc</td>
                        <td>
                            <a href="@Url.Action("detailInfo", "product", new { id = m.goods_id})">查看</a>
                        </td>
                    </tr>
                }
            }
        </table>
    }



    <script>
        BUI.use('bui/overlay', function (overlay) {
            $(function () {
                switch ('@Model.include_tax') {
                    case '0':
                        $("input[name='include_tax']").get(0).checked = true;
                        break;
                    default:
                        $("input[name='include_tax']").get(1).checked = true;
                        break;
                }
                switch ('@Model.jingjia_satus') {
                    case '0':
                        $("input[name='jingjia_satus']").get(0).checked = true;
                        break;
                    case '1':
                        $("input[name='jingjia_satus']").get(1).checked = true;
                        break;
                    default:
                        $("input[name='jingjia_satus']").get(2).checked = true;
                        break;
                }

                var validator = $('form').validate({
                    errorLabelContainer: $("#errorContainer"),
                    errorElement: "span",
                    rules: {
                        img_url: { required: true },
                        include_tax: { required: true },
                        base_price: { required: true, IsNumber: true },
                        step_price: { required: true, IsNumber: true},
                        baozheng_price: { required: true, IsNumber: true },
                        jingjia_satus: { required: true },
                        stay_miniutes: { required: true, IsNumber: true },
                        begin_time: { required: true },
                        real_end_time: { required: true }
                    },
                    submitHandler: function (form) {
                        $(form).ajaxSubmit(function (result) {
                            ShowActionResult(result, function () { self.location = document.referrer; });
                        });
                    }
                });

            });
        });
    </script>
</form>
